<template>
	<view class="device_container">
		<view class="card_container">
			<view class="device_item">
				<view class="item_label">
					操作系统
				</view>
				<view class="item_content">
					{{deviceInfo.osName}} {{deviceInfo.osVersion}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					设备品牌
				</view>
				<view class="item_content">
					{{deviceInfo.deviceBrand}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					设备型号
				</view>
				<view class="item_content">
					{{deviceInfo.deviceModel}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					网络类型
				</view>
				<view class="item_content">
					{{extraInfo.networkType}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					系统语言
				</view>
				<view class="item_content">
					{{deviceInfo.hostLanguage}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					屏幕亮度
				</view>
				<view class="item_content">
					{{extraInfo.luminance}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					屏幕宽度
				</view>
				<view class="item_content">
					{{deviceInfo.screenWidth}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					屏幕高度
				</view>
				<view class="item_content">
					{{deviceInfo.screenHeight}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					设备像素比
				</view>
				<view class="item_content">
					{{deviceInfo.devicePixelRatio}}
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					电量
				</view>
				<view class="item_content">
					{{extraInfo.electricQuantity}}%
					<text v-if="extraInfo.isCharging">(充电中)</text>
				</view>
			</view>
			<view class="device_item">
				<view class="item_label">
					微信版本号
				</view>
				<view class="item_content">
					{{deviceInfo.hostVersion}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				deviceInfo:{
					deviceBrand:"", // 设备名称
					deviceModel:"", // 设备型号
					osVersion:"", // 操作系统
					hostLanguage: "", // 语言
					screenWidth:"", // 屏幕宽度
					screenHeight:"", // 屏幕高度
					devicePixelRatio:"", //像素比
					hostVersion:"", // 微信版本号
				},
				extraInfo:{
					luminance:"", //亮度
					electricQuantity:"",//电量
					isCharging:false, //是否在充电
					networkType:"", //网络状态
				}
			}
		},
		onShow() {
			this.getDeviceInfo()
			
		},
		methods:{
			getDeviceInfo(){
				let that = this
				uni.getSystemInfo({
					success: function(res) {
						console.log("设备",res);
						that.deviceInfo = res
					}
				})
				uni.getScreenBrightness({
					success: function (res) {
						that.extraInfo.luminance = res.value
					}
				});
				uni.getBatteryInfo({
				  success: (res) => {
					that.extraInfo.electricQuantity = res.level
					that.extraInfo.isCharging = res.isCharging
				  }
				})
				uni.getNetworkType({
					success: function (res) {
						that.extraInfo.networkType = res.networkType
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.device_container{
		.card_container{
			width: 90%;
			height: 90vh;
			margin: 0 auto;
			border-radius: 20rpx;
			box-shadow: 0 0 5px #8799a3;
			background-color: #fff;
			margin-top: 20rpx;
			padding: 40rpx;
			box-sizing: border-box;
			overflow-y: scroll;
			.device_item{
				display: flex;
				align-items: center;
				height: 100rpx;
				border-bottom: 1px solid #f7f7f7;
				.item_label{
					font-weight: bold;
					width: 35%;
				}
				.item_content{
					
				}
			}
		}
	}
</style>